function setUrlParam(url,param){
    let str = ''
    for(let key in param){
        if(str){
            str = str + "&" + key + '=' + param[key]
        } else {
            str = url + "?" + key + '=' + param[key]
        }
    }
    return str
}


function handleData(data){
    let list = [],
    map = {}
    data.forEach(item=> {
        list.push({label: item.title, value: item.id})
        map[item.code] = item.title
    })
    return {list,map}
}

// const timer = useRef(null)
// const [data, setData] = useState()

// useEffect(()=> {
//     loopQueryData()
// },[])

// const loopQueryData = () => {
//     let resData = await queryData

//     let result = resData.sort((a,b)=> b.updateTime - a.updateTime)
//     setData(result)

//     let flag = result.some(item => item.status === 1)
//     if(flag){
//         timer.current = setTimeout(()=> {
//             loopQueryData()
//             timer.current = null 
//             clearTimeout(timer.current)
//         }, 5000)
//     } else {
//         timer.current = null 
//         timer.current && clearTimeout(timer.current)
//     }
// }

const isObj = (target) => {
    return Object.prototype.toString.apply(target) === '[object Object]'
}

const isEqualObj = (obj1,obj2) => {
    if(!obj1 || !obj2){
        return obj1 === obj2
    }

    let keys1 = Object.keys(obj1)
    let keys2 = Object.keys(obj2)
    if(keys1.length !== keys2.length){
        return false
    }

    let result = true
    for(let key of keys1){
        if(keys1.includes(key) && keys2.includes(key)){
            result = isEqualObj(obj1[key],obj2[key])
        } else {
            result = false
            break
        } 
    }
    return result

}


function debounce(fn,wait,immediate){
    let timer = null
    return function() {
        if(timer){
            clearTimeout(null)
        }
        if(immediate){
            let callnow = !timer
            timer = setTimeout(()=> {
                timer = null
            },wait)
            if(callnow){
                fn.apply()
            }
        } else {
            timer = setTimeout(()=> {
                fn.apply()
                timer = null
            },wait)
        }
    }
}

function thrrole(fn,wait,immediate){
    let timer, pre = 0
    return function(){
        if(immediate){
            let now = Data.now()
            if(now - pre > wait){
                fn.apply()
                pre = now
            }

        } else {
            if(!timer){
               timer =  setTimeout(()=> {
                   fn.apply()
                   timer = null
                   clearTimeout(timer)
               },wait)
            }
        }
    }
}

function getTreeData(list,pid){
    let result = list.filter(item => item.pid === pid)
    result.forEach(item=> {
        let arr = getTreeData(list,item.id)
        if(arr.length){
            item.children = arr
        }
    })
    return result
}

let list = [
    {id: 1, name:'22',pid: 0},
    {id: 2, name: '33', pid: 1},
    {id: 3,name: 'ee',pid: 2},
    {id: 11,name: 'ww',pid: 0},
    {id: 22,name: 'ii',pid: 11}
]

console.log(getTreeData(list,0))

